using System;
using System.Threading.Tasks;
using JlPay.Sdk.Core;
using JlPay.Sdk.Services;
using JlPay.Sdk.Models.BaseData;

namespace JlPay.Sdk.Examples.Base.BankList
{
    /// <summary>
    /// 银行总行信息查询独立示例程序
    /// </summary>
    public class BankListDemo
    {
        /// <summary>
        /// 主程序入口
        /// </summary>
        /// <param name="args">命令行参数</param>
        /// <returns>任务</returns>
        public static async Task Main(string[] args)
        {
            Console.WriteLine("==========================================");
            Console.WriteLine("===== 银行总行信息查询独立示例程序 =====");
            Console.WriteLine("==========================================");
            Console.WriteLine();

            await BankListDemoAsync();

            Console.WriteLine("==========================================");
            Console.WriteLine("===== 示例运行完毕 =====");
            Console.WriteLine("==========================================");
        }

        /// <summary>
        /// 创建配置对象
        /// </summary>
        /// <returns>配置对象</returns>
        private static Config CreateConfig()
        {
            return DemoConfig.CreateConfigWithCrypto();
        }

        /// <summary>
        /// 构建银行总行信息查询请求
        /// </summary>
        /// <returns>请求对象</returns>
        private static BankListRequest BuildBankListRequest()
        {
            var request = new BankListRequest
            {
                BankName = "中国银行",
                Limit = 10,
                Offset = 0
            };

            return request;
        }

        /// <summary>
        /// 银行总行信息查询示例
        /// </summary>
        public static async Task BankListDemoAsync()
        {
            Console.WriteLine("开始执行银行总行信息查询示例");
            
            try
            {
                // 创建配置对象和基础数据服务
                var config = CreateConfig();
                var baseDataService = new BaseDataService(config);
                
                // 创建银行总行信息查询请求
                var request = BuildBankListRequest();
                
                // 发送请求
                var response = await baseDataService.QueryBankListAsync(request);
                
                // 处理响应结果
                response.HandleResponse("查询银行总行信息", config);
            }
            catch (Exception ex)
            {
                var config = CreateConfig();
                var response = new BankListResponse();
                response.HandleResponseWithException("查询银行总行信息", config, ex);
            }
            
            Console.WriteLine("银行总行信息查询示例执行完毕");
        }
    }
} 